﻿using System;
using System.Collections.Generic;
using System.Linq;

using IdeaNMR.Shared;
using IdeaNMR.Web.Core;

namespace IdeaNMR.Web
{
    public partial class AboutMe : IdeaNMR_BasePage
    {
        protected new void Page_PreInit(object sender, EventArgs e)
        {
            base.Page_PreInit(sender, e);
        }

        protected void Page_PreLoad(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Master.Title = "About Myself";
                tbFirstName.MaxLength = tbMidName.MaxLength = tbLastName.MaxLength = Sanitar.Username.MaxLength;
                revFirstName.Text = revMidName.Text = revLastName.Text = Sanitar.Username.ErrorMsg;
                revFirstName.ValidationExpression = revMidName.ValidationExpression = revLastName.ValidationExpression = Sanitar.Username.ValidationRegex;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                User thisUser = this.UserData.GetUser();
                tbUsername.Text = thisUser.Username;
                tbFirstName.Text = (thisUser.Firstname != null) ? thisUser.Firstname : string.Empty;
                tbMidName.Text = (thisUser.Middlename != null) ? thisUser.Middlename : string.Empty;
                tbLastName.Text = (thisUser.Lastname != null) ? thisUser.Lastname : string.Empty;
            }
        }
        protected void butSave_Click(object sender, EventArgs e)
        {
            this.UserData.Modify(tbFirstName.Text, tbMidName.Text, tbLastName.Text);
        }
    }
}